//package com.fecean.aabbc.netty.server.prod3;
//
//import com.fecean.aabbc.netty.message3.MessageRegister;
//import io.netty.channel.ChannelHandler;
//import io.netty.channel.ChannelHandlerContext;
//import io.netty.channel.SimpleChannelInboundHandler;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//import java.util.Optional;
//
///**
// ** 服务端注册通道处理
// ** ，收到客户端的注册请求后，直接添加到NettyClientChannel中，并把注册信息返回给客户端
// *
// * @author: chenfenghai
// * @version: 1.0
// * @date: 2020-03-05 15:59
// * @blame Team
// */
//@Slf4j
//@Component
//@ChannelHandler.Sharable
//public class NettyServerRegisterHandler extends SimpleChannelInboundHandler<MessageRegister> {
//
//    /**
//     ** 客户端通道
//     */
//    @Resource
//    NettyClientGroup nettyClientGroup;
//
//    @Override
//    protected void channelRead0(ChannelHandlerContext ctx, MessageRegister messageRegister) throws Exception {
//        nettyClientGroup.addClientChannel(
//                messageRegister.getTenantId(),
//                messageRegister.getCinemaCode(),
//                ctx.channel());
//        log.info("客户端[{}-{}]注册，当前数量[{}]",
//                messageRegister.getTenantId(),
//                messageRegister.getCinemaCode(),
//                nettyClientGroup.getSize());
//        ctx.channel().writeAndFlush(messageRegister);
//    }
//
//    @Override
//    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
//        Optional<NettyClient> clientOptional = nettyClientGroup.getClientChannel(ctx.channel());
//        clientOptional.ifPresent(nettyClient -> {
//            nettyClientGroup.removeClientChannel(ctx.channel());
//            log.info("客户端[{}-{}]退出，当前数量[{}]",
//                    nettyClient.getTenantId(), nettyClient.getCinemaCode(), nettyClientGroup.getSize());
//        });
//        ctx.fireChannelInactive();
//    }
//}
